package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

@Mapper
public interface ReportMapper {


    @Select("select sum(amount) from orders where order_time between #{beginTime} and #{endTime} and status=#{status}")
    Double turnoverStatistics(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    @Select("select count(0) from user where create_time< #{endTime}")
    Integer totalUserList(LocalDateTime beginTime, LocalDateTime endTime);

    @Select("select count(0) from user where  create_time between #{beginTime} and #{endTime}")
    Integer newUserList(LocalDateTime beginTime, LocalDateTime endTime);

    @Select("select count(0) from orders where order_time between #{beginTime} and #{endTime}")
    Integer orderCountList(LocalDateTime beginTime, LocalDateTime endTime);

    @Select("select count(0) from orders where order_time between #{beginTime} and #{endTime} and status=5")
    Integer validOrderCountList(LocalDateTime beginTime, LocalDateTime endTime);

//    @Select("select * from orders where order_time between #{of} and #{of1}")
//    ArrayList<Orders> OrderList(LocalDateTime of, LocalDateTime of1);
//
//    @Select("select * from order_detail where order_id=#{id}")
//    ArrayList<OrderDetail> OrderDetailList(Long id);

    @Select("select od.name,sum(od.number) as number from order_detail as od ,orders as o" +
            " where od.order_id=o.id and o.status=5 and o.order_time between #{begin} and #{end} group by od.name order by number desc limit 0,10")
    List<GoodsSalesDTO> top10(LocalDateTime begin, LocalDateTime end);
}
